package com.szewec.ps.ui.tabbar;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.ZoomControls;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.BDLocation;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.MyLocationData;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.map.PolylineOptions;
import com.baidu.mapapi.map.UiSettings;
import com.baidu.mapapi.model.LatLng;
import com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter;
import com.szewec.ps.R;
import com.szewec.ps.base.Constants;
import com.szewec.ps.base.ListBaseAdapter;
import com.szewec.ps.base.SuperViewHolder;
import com.szewec.ps.databinding.FragmentHomeBinding;
import com.szewec.ps.model.PresentValue;
import com.szewec.ps.model.projectandstage.Project;
import com.szewec.ps.model.task.SurveyObjectModel;
import com.szewec.ps.myview.toast.bamtoast.BamToast;
import com.szewec.ps.ui.common.SearchSurveyObjectActivity;
import com.szewec.ps.ui.common.SelectCoordinatesActivity;
import com.szewec.ps.ui.road.facilities.intersection.task.RoadIntersectionTaskActivity;
import com.szewec.ps.ui.road.facilities.investigation.task.RoadInvestigationTaskActivity;
import com.szewec.ps.ui.road.facilities.traffic.RoadIntersectionInvestigationTaskActivity;
import com.szewec.ps.ui.road.facilities.traffic.RoadTrafficInvestigationTaskActivity;
import com.szewec.ps.util.CoorModelChangeUtil;
import com.szewec.ps.util.LogUtil;
import com.szewec.ps.util.PermissionsUtils;
import com.szewec.ps.util.PreferincesContext;
import com.szewec.ps.util.SharedPreferencesUtil;
import com.szewec.ps.util.StringUtils;
import com.szewec.ps.util.dialog.LoadingDialog;
import com.szewec.ps.util.okhttp.OkHttp;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

//首页fragment
public class HomeFragment extends Fragment implements TabHost.OnTabChangeListener {
    private static final String TAG = "HomeFragment";
    private static final String BUNDLE_KEY = "surveyObject";
    private Unbinder unbinder;
    private FragmentHomeBinding binding;
    private MapView mMapView;
    private BaiduMap mBaiduMap;
    private LocationClient mLocationClient;
    private BDLocation bdlocation;
    //是否第一次定位
    private boolean isFirstLocate = true;
    /**
     * markerList
     */
    List<OverlayOptions> markerOptionsList = new ArrayList<>();
    /**
     * 当前点击的marker
     */
    private SurveyObjectModel selectedModel;
    int[] zoom = new int[]{50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 25000, 50000, 100000};


    /**
     * 本地存储的项目和阶段
     */
    private String selectedProjectId;
    private String selectedProjectName;

    /**
     * recycleView相关
     */
    private DataAdapter projectDataAdapter;
    private LRecyclerViewAdapter projectLRecyclerViewAdapter;
    private List<Project> projectList = new ArrayList<>();
    /**
     * 是否在选择项目
     */
    private boolean isOpened = false;

    private Drawable down;
    private Drawable up;
    private MyFragmentTabHost tabHost;
    private LoadingDialog loadingDialog;
    private String address;

    private StartInvestigationDialog dialog;

    /**
     * 调查对象数组
     */
    private List<SurveyObjectModel> surveyObjectModelList = new ArrayList<>();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // 1、对布局需要绑定的内容进行加载
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_home, container, false);

        // 2、获取到视图
        View inflate = binding.getRoot();
        unbinder = ButterKnife.bind(this, inflate);
        loadingDialog = LoadingDialog.getInstance(getActivity());

        down = getActivity().getDrawable(R.drawable.down_dark_arrow);
        up = getActivity().getDrawable(R.drawable.up_dark_arrow);

        PermissionsUtils.getInstance().checkPermissions(getActivity(), new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION,
                        Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE},
                new PermissionsUtils.IPermissionsResult() {
                    @Override
                    public void passPermissons() {
                        LogUtil.i(TAG, "权限通过");
                        initData();
                        initView();
                        initMap();
                        address = (String) SharedPreferencesUtil.getData(PreferincesContext.BD_ADDRESS, "");
                    }

                    @Override
                    public void forbitPermissons() {
                        LogUtil.i(TAG, "权限被禁止");
                    }
                });

        tabHost = getActivity().findViewById(R.id.tab);
        tabHost.setOnTabChangedListener(this);

        return inflate;
    }

    private void setZoom() {
    }

    @Override
    public void onTabChanged(String tabId) {
        if ("首页".equals(tabId)) {
            if (isOpened) {//已经打开了
                tabHost.setVisibility(View.VISIBLE);
                binding.clSelectProjectAndStage.setVisibility(View.GONE);
                isOpened = false;
                binding.tvProjectName.setCompoundDrawablesWithIntrinsicBounds(null, null, down, null);
            }
        }
    }

    @OnClick({R.id.tv_project_name, R.id.iv_my_location, R.id.rl_layer, R.id.rl_close_layer,
            R.id.rl_map_type_normal, R.id.rl_map_type_satellite, R.id.rl_tool, R.id.tv_marker, R.id.tv_ranging, R.id.cl_tool_menu,
            R.id.ll_tool_menu, R.id.cl_search, R.id.rl_trajectory, R.id.iv_navigation, R.id.iv_close, R.id.rl_start_survey
    })
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_project_name:
                if (isOpened) {//已经打开了
                    binding.clSelectProjectAndStage.setVisibility(View.GONE);
                    isOpened = false;
                    binding.tvProjectName.setCompoundDrawablesWithIntrinsicBounds(null, null, down, null);
                } else {
                    binding.clSelectProjectAndStage.setVisibility(View.VISIBLE);
                    isOpened = true;
                    binding.tvProjectName.setCompoundDrawablesWithIntrinsicBounds(null, null, up, null);
                }
                break;
            case R.id.iv_my_location:
                //回到我的位置
                navigateTo(bdlocation, 19f);
                break;
            case R.id.rl_layer:
                //图层按钮
                Animation rtl = AnimationUtils.loadAnimation(getActivity(), R.anim.index_layer_rtl);
                rtl.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                        binding.rlLayerActionView.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        binding.rlCloseLayer.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }
                });
                binding.rlLayerActionView.startAnimation(rtl);
                break;
            case R.id.rl_close_layer:
                //隐藏图层视图
                Animation ltr = AnimationUtils.loadAnimation(getActivity(), R.anim.index_layer_ltr);
                ltr.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                        binding.rlCloseLayer.setVisibility(View.INVISIBLE);
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        binding.rlLayerActionView.setVisibility(View.INVISIBLE);
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }
                });
                binding.rlLayerActionView.startAnimation(ltr);
                break;
            case R.id.rl_map_type_normal:
                //普通类型地图
                mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL);
                binding.rlSatellite.setBackground(null);
                binding.ivSatelliteChecked.setVisibility(View.INVISIBLE);
                binding.rlNormal.setBackgroundColor(getActivity().getResources().getColor(R.color.C2574FF));
                binding.ivNormalChecked.setVisibility(View.VISIBLE);
                break;
            case R.id.rl_map_type_satellite:
                //卫星类型地图
                mBaiduMap.setMapType(BaiduMap.MAP_TYPE_SATELLITE);
                binding.rlNormal.setBackground(null);
                binding.ivNormalChecked.setVisibility(View.INVISIBLE);
                binding.rlSatellite.setBackgroundColor(getActivity().getResources().getColor(R.color.C2574FF));
                binding.ivSatelliteChecked.setVisibility(View.VISIBLE);
                break;
            case R.id.rl_tool:
                //显示工具菜单
                binding.clToolMenu.setVisibility(View.VISIBLE);
                break;
            case R.id.tv_marker:
                //添加标注点
                showUnfinish();
                break;
            case R.id.tv_ranging:
                //测距
                Intent intent = new Intent(getActivity(), SelectCoordinatesActivity.class);
                PresentValue<String> presentValue = new PresentValue<>(Constants.SELECT_COOR_FLAG.RANGING, null);
                intent.putExtra(Constants.EXTRA_KEY.SELECT_COOR, presentValue);
                startActivity(intent);
                break;
            case R.id.cl_tool_menu:
                //关闭工具菜单
                binding.clToolMenu.setVisibility(View.GONE);
                break;
            case R.id.ll_tool_menu:
                //拦截点击事件
                break;
            case R.id.cl_search:
                //搜索框
                Intent searchIntent = new Intent(getActivity(), SearchSurveyObjectActivity.class);
                startActivityForResult(searchIntent,Constants.REQUEST_CODE.SEARCH_SURVEY_OBJECT);
                break;
            case R.id.rl_trajectory:
                //轨迹
                showUnfinish();
                break;
            case R.id.iv_navigation:
                //导航
                showUnfinish();
                break;
            case R.id.iv_close:
                binding.clStartSurvey.setVisibility(View.GONE);
                break;
            case R.id.rl_start_survey:
                //跳转到调查首页
                //TODO 根据调查对象类型跳转
                switch (selectedModel.getType()){
                    case Constants.SurveyObjectType.ROAD_SECTION_FACILITIES://路段设施
                        Intent intentTask = new Intent(getActivity(), RoadInvestigationTaskActivity.class);
                        PresentValue<SurveyObjectModel> presentValueTask = new PresentValue<>(Constants.PRESENT_VALUE_FLAG.ADD, selectedModel);
                        intentTask.putExtra(Constants.EXTRA_KEY.ROAD_INVESTIGATION_TASK, presentValueTask);
                        startActivity(intentTask);
                        break;
                    case Constants.SurveyObjectType.ROAD_INTERSECTION_FACILITIES://路口设施
                        Intent intersectionIntent = new Intent(getActivity(), RoadIntersectionTaskActivity.class);
                        PresentValue<SurveyObjectModel> intersectionPresentValue = new PresentValue<>(Constants.PRESENT_VALUE_FLAG.ADD, selectedModel);
                        intersectionIntent.putExtra(Constants.EXTRA_KEY.ROAD_INTERSECTION_TASK, intersectionPresentValue);
                        startActivity(intersectionIntent);
                        break;
                    case Constants.SurveyObjectType.ROAD_SECTION_TRAFFFIC://路段交通量
                        Intent roadSectionTrafficIntentTask = new Intent(getActivity(), RoadTrafficInvestigationTaskActivity.class);
                        PresentValue<SurveyObjectModel> roadSectionTrafficPresentValue = new PresentValue<>(Constants.PRESENT_VALUE_FLAG.ADD, selectedModel);
                        roadSectionTrafficIntentTask.putExtra(Constants.EXTRA_KEY.ROAD_TRAFFIC_INVESTIGATION_TASK, roadSectionTrafficPresentValue);
                        startActivity(roadSectionTrafficIntentTask);
                        break;
                    case Constants.SurveyObjectType.ROAD_INTERSECTION_TRAFFFIC://路口交通量
                        Intent roadIntersectionIntentTask = new Intent(getActivity(), RoadIntersectionInvestigationTaskActivity.class);
                        PresentValue<SurveyObjectModel> roadIntersectionPresentValue = new PresentValue<>(Constants.PRESENT_VALUE_FLAG.ADD, selectedModel);
                        roadIntersectionIntentTask.putExtra(Constants.EXTRA_KEY.ROAD_TRAFFIC_INVESTIGATION_TASK, roadIntersectionPresentValue);
                        startActivity(roadIntersectionIntentTask);
                        break;
                }
                break;
        }
    }

    private void initData() {
        String projectListString = (String) SharedPreferencesUtil.getData(PreferincesContext.PROJECT_AND_STAGE_INFO, "");
        selectedProjectId = (String) SharedPreferencesUtil.getData(PreferincesContext.PROJECT_ID, "");
        selectedProjectName = (String) SharedPreferencesUtil.getData(PreferincesContext.PROJECT_NAME, "");
        if (StringUtils.isNotEmpty(projectListString)) {
            List<Project> projects = JSON.parseArray(projectListString, Project.class);
            for (Project project : projects) {
                if (project.getId().equals(selectedProjectId)) {
                    project.setChecked(true);
                }
            }
            projectList = projects;
        }
        getSurveyByProjectId(selectedProjectId);
    }

    private void initView() {
        projectDataAdapter = new DataAdapter(getActivity());
        projectLRecyclerViewAdapter = new LRecyclerViewAdapter(projectDataAdapter);
        binding.lrvProject.setAdapter(projectLRecyclerViewAdapter);
        LinearLayoutManager linearLayoutManager1 = new LinearLayoutManager(getActivity());
        binding.lrvProject.setLayoutManager(linearLayoutManager1);
        binding.lrvProject.setLoadMoreEnabled(false);
        binding.lrvProject.setPullRefreshEnabled(false);

        refreshProjectAndStage();
    }

    /**
     * 根据项目ID查询调查对象
     */
    private void getSurveyByProjectId(String projectId){
        HashMap<String,Object> param = new HashMap<>();
        param.put("projectId",projectId);
        OkHttp.get("/tpms-plan-service/api/task/get-survey-object-by-params", param, null, new OkHttp.MyCallback() {
            @Override
            public void onSuccess(String result) {
                LogUtil.i("查询调查对象结果:",result);
                JSONArray data = JSONObject.parseObject(result).getJSONArray("data");
                if (data != null && data.size() > 0){
                    surveyObjectModelList = data.toJavaList(SurveyObjectModel.class);
                    //提取调查对象的坐标
                    getSurveyObjectCoor();
                }else {
                    surveyObjectModelList.clear();
                    markerOptionsList.clear();
                    if (mBaiduMap != null){
                        mBaiduMap.clear();
                    }
                }
            }
        });
    }

    /**
     * 提取调查对象的坐标,添加到地图上
     */
    private void getSurveyObjectCoor(){
        markerOptionsList.clear();
        mBaiduMap.clear();
        for (SurveyObjectModel model:surveyObjectModelList){
            List<LatLng> points = CoorModelChangeUtil.changeToLatLng(model.getCoordinate());
            Bundle bundle = new Bundle();
            bundle.putSerializable(BUNDLE_KEY,model);
            OverlayOptions overlays;
            if (points.size() == 1){//单点
                overlays = new MarkerOptions()
                        .position(points.get(0))
                        .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_road_1))
                        .animateType(MarkerOptions.MarkerAnimateType.grow)
                        .extraInfo(bundle);
            }else {
                overlays = new PolylineOptions()
                        .width(20)
                        .color(0xAA2574FF)
                        .points(points)
                        .extraInfo(bundle);
            }
            markerOptionsList.add(overlays);
        }
        mBaiduMap.addOverlays(markerOptionsList);
    }

    private void doOverlayClick(SurveyObjectModel surveyObjectModel){
        //显示信息框
        binding.clStartSurvey.setVisibility(View.VISIBLE);
        binding.tvSurveyObjectName.setText(surveyObjectModel.getSurveyName());
        selectedModel = surveyObjectModel;
    }

    private void showUnfinish() {
        BamToast.showText(getActivity(), "敬请期待", 1000);
    }

    @Override
    public void onStart() {
        super.onStart();
        String projectName = (String) SharedPreferencesUtil.getData(PreferincesContext.PROJECT_NAME, "");
        binding.tvProjectName.setText(projectName);
    }

    private void initMap() {
        // 隐藏百度的LOGO
        mMapView = binding.bmapView;
        View child = mMapView.getChildAt(1);
        if (child != null && (child instanceof ImageView || child instanceof ZoomControls)) {
            child.setVisibility(View.GONE);
        }
        // 不显示地图上比例尺
        mMapView.showScaleControl(false);
        // 不显示地图缩放控件（按钮控制栏）
        mMapView.showZoomControls(false);

        mBaiduMap = mMapView.getMap();
        //开启地图的定位图层
        mBaiduMap.setMyLocationEnabled(true);

        //通过LocationClient发起定位
        //定位初始化
        mLocationClient = new LocationClient(getActivity().getApplicationContext());


        //通过LocationClientOption设置LocationClient相关参数
        LocationClientOption option = new LocationClientOption();
        option.setOpenGps(true); // 打开gps
        option.setCoorType("bd09ll"); // 设置坐标类型
        option.setScanSpan(1000);
        option.setIsNeedAddress(true);

        //设置locationClientOption
        mLocationClient.setLocOption(option);

        //注册LocationListener监听器
        MyLocationListener myLocationListener = new MyLocationListener();
        mLocationClient.registerLocationListener(myLocationListener);
        //开启地图定位图层
        mLocationClient.start();
        //悬浮物监听
        initMarkClickListener();
        //线点击事件
        initPolyLineClickListener();
        //手势
        UiSettings settings = mBaiduMap.getUiSettings();
        settings.setOverlookingGesturesEnabled(false);//屏蔽双指下拉时变成3D地图
        settings.setRotateGesturesEnabled(false);//屏蔽旋转
    }

    private void initMarkClickListener() {
        mBaiduMap.setOnMarkerClickListener(marker -> {
            SurveyObjectModel surveyObjectModel = (SurveyObjectModel) marker.getExtraInfo().getSerializable(BUNDLE_KEY);
            doOverlayClick(surveyObjectModel);
            return true;
        });
    }

    private void initPolyLineClickListener(){
        mBaiduMap.setOnPolylineClickListener(polyline -> {
            SurveyObjectModel surveyObjectModel = (SurveyObjectModel) polyline.getExtraInfo().getSerializable(BUNDLE_KEY);
            doOverlayClick(surveyObjectModel);
            return true;
        });
    }

    private void refreshProjectAndStage() {
        projectDataAdapter.setDataList(projectList);
        projectDataAdapter.notifyDataSetChanged();
    }

    private void doSelected(Project project) {
        selectedProjectId = project.getId();
        SharedPreferencesUtil.putData(PreferincesContext.PROJECT_ID, project.getId());
        SharedPreferencesUtil.putData(PreferincesContext.PROJECT_NAME, project.getProjectName());
        for (Project project1 : projectList) {
            if (project1.getId().equals(project.getId())) {
                project1.setChecked(true);
            } else {
                project1.setChecked(false);
            }
        }
        refreshProjectAndStage();
        binding.tvProjectName.setText(project.getProjectName());
        binding.clSelectProjectAndStage.setVisibility(View.GONE);
        isOpened = false;
        binding.tvProjectName.setCompoundDrawablesWithIntrinsicBounds(null, null, down, null);

        //刷新marker
        getSurveyByProjectId(selectedProjectId);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == Constants.REQUEST_CODE.SEARCH_SURVEY_OBJECT){
            if (resultCode == Constants.RESULT_CODE.SEARCH_SURVEY_OBJECT){
                Bundle bundle = data.getExtras();
                SurveyObjectModel surveyObjectModel = (SurveyObjectModel) bundle.getSerializable(Constants.EXTRA_KEY.SEARCH_SURVEY_OBJECT);
                surveyObjectModelList.clear();
                surveyObjectModelList.add(surveyObjectModel);
                getSurveyObjectCoor();
            }else {
                getSurveyByProjectId(selectedProjectId);
            }
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        //就多一个参数this
        PermissionsUtils.getInstance().onRequestPermissionsResult(getActivity(), requestCode, permissions, grantResults);
    }

    public class MyLocationListener extends BDAbstractLocationListener {
        @Override
        public void onReceiveLocation(BDLocation location) {
            //mapView 销毁后不在处理新接收的位置
            if (location == null || mMapView == null) {
                return;
            }
            bdlocation = location;

            if (!address.equals(bdlocation.getAddrStr())) {
                address = bdlocation.getAddrStr();
                LogUtil.i(TAG, "定位位置:" + bdlocation.getAddrStr());
                //将地址存储
                SharedPreferencesUtil.putData(PreferincesContext.BD_ADDRESS, bdlocation.getAddrStr());
            }
            navigateToLocation(location);
        }
    }

    public void navigateToLocation(BDLocation location) {
        if (isFirstLocate) {
            MyLocationData.Builder locationBuilder =
                    new MyLocationData.Builder();
            locationBuilder.latitude(location.getLatitude());
            locationBuilder.longitude(location.getLongitude());
            MyLocationData locationData = locationBuilder.build();
            mBaiduMap.setMyLocationData(locationData);
            //初次进入界面定位本地
            navigateTo(location, 19f);
        }
    }

    /**
     * 移动到指定位置
     *
     * @param location
     * @param v
     */
    public void navigateTo(BDLocation location, float v) {
        LatLng ll = new LatLng(location.getLatitude(), location.getLongitude());
        MapStatusUpdate update = MapStatusUpdateFactory.newLatLng(ll);
        mBaiduMap.animateMapStatus(update);
        update = MapStatusUpdateFactory.zoomTo(v);//设置比例
        mBaiduMap.animateMapStatus(update);
        /*判断baiduMap是已经移动到指定位置*/
        if (mBaiduMap.getLocationData() != null)
            if (mBaiduMap.getLocationData().latitude == location.getLatitude()
                    && mBaiduMap.getLocationData().longitude == location.getLongitude()) {
                isFirstLocate = false;
            }
    }

    private class DataAdapter extends ListBaseAdapter<Project> {


        public DataAdapter(Context context) {
            super(context);
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_common_string_2;
        }

        @Override
        public void onBindItemHolder(SuperViewHolder holder, int position) {
            TextView title = holder.getView(R.id.tv_common_title);
            ImageView checkedIv = holder.getView(R.id.iv_checked);

            Project project = mDataList.get(position);
            title.setText(project.getProjectName());
            if (project.isChecked()) {
                checkedIv.setVisibility(View.VISIBLE);
            } else {
                checkedIv.setVisibility(View.GONE);
            }
            //行点击监听事件
            holder.itemView.setOnClickListener(view -> {
                System.out.println("当前选择的是:" + project.getProjectName());
                doSelected(project);
            });
        }
    }

    @Override
    public void onResume() {
        //在activity执行onResume时执行mMapView. onResume ()，实现地图生命周期管理
        if (mMapView != null) {
            mMapView.onResume();
        }
        super.onResume();
    }

    @Override
    public void onPause() {
        //在activity执行onResume时执行mMapView. onResume ()，实现地图生命周期管理
        if (mMapView != null) {
            mMapView.onPause();
        }
        super.onPause();
    }


    @Override
    public void onDestroy() {
        //在activity执行onResume时执行mMapView. onResume ()，实现地图生命周期管理
        mLocationClient.stop();
        mBaiduMap.setMyLocationEnabled(false);
        if (mMapView != null) {
            mMapView.onDestroy();
        }
        mMapView = null;
        super.onDestroy();
    }
}
